<template>
  <div class="app-container">
    <div class="video">
      <div class="video-l">
        <div  class="prism-player" id="J_prismPlayer"></div>
        <!-- <video controls preload='true' src="https://vdept.bdstatic.com/3857736362314979695735596a4e5857/4b50464e535a4b32/572d08a8681d424be3b4a52b75f75c61eba39794114f7381326d1624bb387a8629ec54c7f32908003f2630d367646d41.mp4?auth_key=1594896653-0-0-6f1ec7e9af3ae35d4b83254a1a269143"></video> -->
      </div>
      <div class="video-r">
        <div class="teacher">
          <div class="avatar">
            <img :src="teacher.avatar ? teacher.avatar : null" alt="">
            <div class="avatar-text">
              <span>{{teacher.name}}</span>
              <span>{{teacher.level === 1 ? '高级讲师' : '首席讲师'}}</span>
            </div>
          </div>
          <div class="teacher-content">
            {{teacher.career}}
          </div>
        </div>
        <div class="video-title">{{items.title}}</div>
        <p v-html="items.description"></p>
        <!-- <div class="close">x</div> -->
      </div>
    </div>
    <div class="jianjie">
      简介：<span v-html="items.description"></span>
    </div>
    <div class="mulu">
      <!-- 大分类 -->
      <div v-if="detail && detail.length !== 0" class="mululist" v-for="(item,index) in detail" :key="index">
        <p>{{item.title}} <span v-if="item.eduChapterTest && item.eduChapterTest.length !== 0" @click="ceshi(item)">章节测试</span></p>
        <!-- 子目录 -->
        <div class="zimulu" @click="goPlay(item1,index,index1)" :class="index === bigIndex && index1 === smallIndex ? 'active' : ''" v-for="(item1,index1) in item.children" :key="index1">
          <div class="title">
            <div class="icons">
              <i class="el-icon-caret-right" />
            </div>
            {{item1.title}}<span></span>
          </div>
        </div>
      </div>
      <div class="null" v-if="!detail && detail.length == 0">暂无目录信息</div>
    </div>
  </div>
</template>

<script>
  import { addZhangjie,qiantaoList,deleteZhangjie,selectZhangjie,updateZhangjie,getPlayauth,getTeacherInfo } from '@/api/people'
  export default {
    data(){
      return{
        detail: null,
        items: {},
        bigIndex: null,
        smallIndex: null,
        teacher: {
          avatar: ''
        }
      }
    },
    mounted(){
      const tempdata = JSON.parse(sessionStorage.getItem('videoDetail'))
      this.items = tempdata
      console.log('detail',this.items)
      this.getZhangjie(tempdata.id)
      this.getJsInfo(tempdata.teacherId)
      // this.initVideo()
    },
    methods:{
      initVideo(videoId,auth){
        console.log('播放器初始化')
        var player = new Aliplayer({
          id: 'J_prismPlayer',
          width: '100%',
          height: '100%',
          autoplay: true,
          //支持播放地址播放,此播放优先级最高
          // source : '播放url',
          //播放方式二：点播用户推荐
          vid: videoId,
          playauth: auth,
          cover: 'http://liveroom-img.oss-cn-qingdao.aliyuncs.com/logo.png',
          //encryptType:1, //当播放私有加密流时需要设置。
          },function(player){
            console.log('播放器创建好了。')
          });
      },
      /**
       * 获取章节目录
       */
      getZhangjie(id){
        qiantaoList(id).then(res => {
          console.log(res)
          this.detail = res.data.items
        })
      },
      /**
       * 点击小节开始播放当前章节
       */
      goPlay(item,index,index1){
        this.bigIndex = index
        this.smallIndex = index1
        console.log(this.bigIndex,this.smallIndex)
        console.log(item)
        getPlayauth(item.videoOriginalName).then(res => {
          console.log(res)
          this.initVideo(item.videoOriginalName,res.data.playAuth)
        })
        // getPlayauth('ef900506a336492ca0fce0ac5c2a7b9f').then(res => {
        //   console.log(res)
        //   this.initVideo('ef900506a336492ca0fce0ac5c2a7b9f',res.data.playAuth)
        // })
      },
      /**
       * 开始章节测试
       */
      ceshi(item){
        this.$router.push({
          name: 'Kaishiceshi',
          params: {
            options: JSON.stringify(item)
          }
        })
      },
      /**
       * 获取讲师信息
       */
      getJsInfo(id){
        getTeacherInfo(id).then(res => {
          console.log('讲师信息',res)
          if(res.data.eduTeacher){
            this.teacher = res.data.eduTeacher
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
/deep/p{
  margin: 0;
}
.null{
  text-align: center;
  font-size: 14px;
  color: #666;
  padding: 15px 0 ;
}
.app-container{
  padding: 20px;
}
.video{
  padding: 20px;
  background: #1c1f21;
  display: flex;
  border-radius: 10px;
  margin-bottom: 10px;
}
.video-l{
  background: #000;
  flex: 1;
  height: 400px;
  position: relative;
  overflow: hidden;
  z-index: 1;
}
.video-l video{
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.video-r{
  padding-left: 20px;
  width: 40%;
  background: #1c1f21;
  position: relative;
  .teacher{
    margin-bottom: 20px;
    .avatar{
      display: flex;
      margin-bottom: 5px;
      >img{
        width: 45px;
        height: 45px;
        border-radius: 50%;
        background: #fff;
        margin-right: 15px;
      }
      .avatar-text{
        font-size: 14px;
        color: #fff;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        >span{
          font-weight: 600;
          &:last-child{
            display: block;
            padding: 3px 5px;
            border-radius: 3px;
            background: #ce2c10;
            color: #fff;
            font-size: 12px;
            text-align: center;
            font-weight: 100;
          }
        }
      }
    }
    .teacher-content{
      font-size: 12px;
      color: rgba(255,255,255,.6);
      line-height: 22px;
    }
  }
  >p{
    font-size: 12px;
    color: rgba(255,255,255,.6);
    line-height: 22px;
    // text-indent: 2em;
    margin: 0;
  }
  .video-title{
    font-size: 14px;
    color: #fff;
    line-height: 24px;
    text-indent: 0em;
    font-weight: 600;
  }
  .close{
    position: absolute;
    right: 10px;
    top: 0px;
    font-size: 18px;
    color: #fff;
    cursor: pointer;
  }
}
.jianjie{
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: 0px 0px 5px rgba(0,0,0,.1);
  font-size: 14px;
  line-height: 25px;
  background: #fff;
  display: flex;
}

.mulu{
  background: #fff;
  box-shadow: 0px 0px 5px rgba(0,0,0,.1);
  font-size: 14px;
  padding: 15px 20px;
  border-radius: 10px;
  .mululist{
    >p{
      font-size: 18px;
      font-weight: 600;
      margin: 15px 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      >span{
        font-size: 12px;
        font-weight: 100;
        padding: 3px 5px;
        background: #18a05e;
        color: #fff;
        border-radius: 3px;
        display: block;
        cursor: pointer;
      }
    }
    .active{
      background: #85ddb2;
      .title .icons{
        background: #18a05e !important;
      }
    }
    .zimulu{
      display: flex;
      justify-content: space-between;
      padding: 10px;
      transition: all .5s;
      border-radius: 5px;
      cursor: pointer;
      &:hover{
        background: #85ddb2;
        // color: #fff;
        .title .icons{
          background: #18a05e;
        }
      }
      .title{
        display: flex;
        align-items: center;
        >span{
          color: #999;
        }
        .icons{
          width: 25px;
          height: 25px;
          border-radius: 50%;
          background: #999;
          color: #fff;
          font-size: 18px;
          display: flex;
          justify-content: center;
          align-items: center;
          transition: all .5s;
          margin-right: 10px;
        }
      }
    }
  }
}

</style>